package com.cheyun.netsalev3.view

import androidx.lifecycle.Observer
import androidx.lifecycle.ViewModel
import androidx.lifecycle.ViewModelProviders
import androidx.recyclerview.widget.RecyclerView
import com.cheyun.netsalev3.R
import com.cheyun.netsalev3.adapter.MyAdapter
import com.cheyun.netsalev3.bean.basedata.Expchar
import com.cheyun.netsalev3.bean.drive.Experience
import com.cheyun.netsalev3.bean.drive.Experience2
import com.cheyun.netsalev3.bean.records.Reserve
import com.cheyun.netsalev3.databinding.ActivityCarDriveDetailsBinding
import com.cheyun.netsalev3.utils.BaseActivity
import com.cheyun.netsalev3.utils.InjectorUtils
import com.cheyun.netsalev3.utils.MySharedPreferences
import com.cheyun.netsalev3.viewmodel.CarDriveDetailsActivityViewModel

class CarDriveDetailsActivity : BaseActivity<ActivityCarDriveDetailsBinding>() {
    override fun initContentView(): Int {
        return R.layout.activity_car_drive_details
    }

    private lateinit var adapter: MyAdapter

    override fun initViewModel(): ViewModel? {
        var list = ArrayList<Reserve>()
//        intent.getSerializableExtra("data")?.apply {
//            var data = this as ArrayList<Reserve>
//            data.forEach(fun(v){
//                if(v.experience!=null && v.experience.size>0){
//                    var s = "";
//                    var i = 1;
//                    v.experience.forEach { if(it.check.equals("1")){
//                        if(s.length>0) s +=','
//                        s += i.toString() +":"+ it.title
//                        i++
//                    } }
//
//                    v.experienceStr = "体验点："+s;
//                }
//            })
//            list.addAll(data)
//        }

        var factory = InjectorUtils.getCarDriveDetailsActivityViewModelFactory(list)
        return ViewModelProviders.of(this, factory).get(CarDriveDetailsActivityViewModel::class.java)
    }

    override fun initData() {
        binding.viewModel?.datalist?.observe(this, Observer { list ->
            adapter.submitList(list)
        })
    }

    override fun initView() {
        adapter = MyAdapter(R.layout.car_drive_list_item, binding.viewModel)
        binding.recyclerView.adapter = adapter
    }

}
